package cn.tedu.yitu.password.controller;

import cn.tedu.yitu.common.web.JsonResult;
import cn.tedu.yitu.password.service.UserService;
import cn.tedu.yitu.protocol.param.UserLoginInfoParam;
import cn.tedu.yitu.protocol.param.UserPhoneVerParam;
import cn.tedu.yitu.protocol.param.UserRegInfoParam;
import cn.tedu.yitu.protocol.vo.UserLoginResultVO;
import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import springfox.documentation.annotations.ApiIgnore;

import javax.servlet.http.HttpServletRequest;

@Slf4j
@RestController
@RequestMapping("/passport")
@Validated
@Api(tags = "1. 单点登录")
public class UserController {
    @Autowired
    private UserService userService;

    @PostMapping("/phoneVerification")
    @ApiOperation("用户手机号验证")
    public JsonResult phoneVerification(@Validated UserPhoneVerParam userPhoneVerParam) {
        log.debug("开始处理【用户手机号验证】的请求，参数：{}", userPhoneVerParam);
        userService.phoneVerification(userPhoneVerParam);
        return JsonResult.ok(1);
    }

    @PostMapping("/reg")
    @ApiOperation("用户注册")
    public JsonResult reg(UserRegInfoParam userRegInfoParam){
        log.debug("开始处理【用户注册】的请求，参数：{}", userRegInfoParam);
        userService.reg(userRegInfoParam);
        return JsonResult.ok(2);
    }

    @PostMapping("/login")
    @ApiOperation("用户登录")
    @ApiOperationSupport(order = 20)
    public JsonResult login(@Validated UserLoginInfoParam userLoginInfoParam,
                            @ApiIgnore HttpServletRequest request) {
        log.debug("开始处理【用户登录】的请求，参数：{}", userLoginInfoParam);
        UserLoginResultVO userLoginResultVO = userService.login(userLoginInfoParam);
        return JsonResult.ok(userLoginResultVO);
    }

}
